﻿/*
-----------------------------------------------------------------------------
This source file is part of Cell Cloud.

Copyright (c) 2009-2012 Cell Cloud Team - cellcloudproject@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/

#ifndef CellMessage_h
#define CellMessage_h

#include "CellPrerequisites.h"

namespace cell
{
/** \addtogroup Core
 *  @{
 */
/** \addtogroup General
 *  @{
 */

/** 描述消息的类。
@author
	Jiangwei Xu
*/
class _CellExport Message : public GeneralAlloc
{
public:
	/** 默认构造函数。
	@remarks
		不建议使用空消息。空消息就表示没有消息。
	*/
	Message(void);

public:
	/** 构造函数。
	*/
	Message(byte* data, uint32 length);

	/** 构造函数。
	*/
	Message(char* data, uint32 length);

	/** 析构函数。
	*/
	virtual ~Message(void);

public:
	/** 获取消息内的数据。
	*/
	uint32 get(byte* data) const;

	/** 获取消息内的数据。
	*/
	uint32 get(char* data) const;

	/** 返回消息长度。
	*/
	FORCEINLINE uint32 length(void) const { return mLength; }

	/** 设置消息数据。
	*/
	void set(char* data, uint32 length);

private:
	byte* mBytes;
	char* mChars;
	uint32 mLength;
};

	/** @} */
	/** @} */
} // end namespace cell

#endif // CellMessage_h
